package ctgu.yao.cloud.controller;


import ctgu.yao.cloud.dto.ResultDTO;
import ctgu.yao.cloud.form.RuleForm;
import ctgu.yao.cloud.po.Companyuser;
import ctgu.yao.cloud.po.Recruitment;
import ctgu.yao.cloud.service.CompanyuserService;
import ctgu.yao.cloud.util.ResultDTOUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import ctgu.yao.cloud.form.RuleForm2;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Y
 * @since 2022-08-16
 */
@RestController
@RequestMapping("/companyuser")
public class CompanyuserController {
    @Autowired
    private CompanyuserService companyuserService;
    //登录
    @GetMapping("/login")
    public ResultDTO login(RuleForm ruleForm){
        ResultDTO resultDTO =this.companyuserService.login(ruleForm);
        return resultDTO;
    }
    //注册
    @GetMapping("/register")
    public ResultDTO register(RuleForm2 ruleForm){
        System.out.println(ruleForm);
        return this.companyuserService.register(ruleForm);
    }
    //人员信息修改
    @GetMapping("/findById/{cuId}")
    public ResultDTO findByID(@PathVariable("cuId") Integer cuId){
        Companyuser companyuser = this.companyuserService.getById(cuId);
        return ResultDTOUtil.success(companyuser);
    }
    @PutMapping("/update")
    public ResultDTO update(@RequestBody Companyuser companyuser){
        boolean update=this.companyuserService.updateById(companyuser);
        if(!update) return ResultDTOUtil.fail();
        return ResultDTOUtil.success(null);
    }

    //查全部
    @RequestMapping("list")
    public List<Companyuser> list(){
        return companyuserService.list();
    }

}
